package com.owen.listener;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.google.zxing.common.StringUtils;
import com.owen.QrCode;
import com.owen.create.CreateQrCode;
import com.owen.entity.PoorData;

import java.io.File;

public class PoorDataListener extends AnalysisEventListener<PoorData> {

    private String fileName;

    public PoorDataListener(String fileName) {
        this.fileName = fileName;
    }

    private QrCode qrCode=new QrCode();

    private String url="https://sl.sxtpgj.com:8100/yhym/?openId=";

    @Override
    public void invoke(PoorData poorData, AnalysisContext analysisContext) {
        String pathname="F:\\工作文件\\2021\\扶贫\\生成二维码\\"+ fileName;
        String phone=poorData.getPoorPhone();
        if(StrUtil.isEmpty(phone)){
            phone="随机"+ RandomUtil.randomInt(10000);
        }
        File file=new File(pathname+"\\"+poorData.getPoorName()+"_"+phone+".jpg");
        qrCode.createQrCode(url+poorData.getPoorId(),file);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
